package app.netant.bt;

import app.netant.NetAntBase;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.enviroment.Enviroment;
import cn.lily.com.lang.number.MathUtil;

public abstract class MargnetPage extends NetAntBase {

	public MargnetPage(String netSite) {
		super(netSite);
	}

	public abstract void analyse();
	public abstract MargnetDetail buildDetail(String url);
	
	protected void analyseHref(String href){
		
		try {
			
			Enviroment.getEnv().getLogBean().beginLog();

			DataTable srcTable = DBFactory.getThreadDB().executeQueryTable("select * from ${schema}.NET_MARGNET_SRC where SRC_URL='"+href+"'");
			if(srcTable.next()){
				return;
			}
			
			MargnetEntity entity = new MargnetEntity();
			entity.setSrcURL(href);
	        
			MargnetDetail detail = this.buildDetail(href);
			
			detail.setEntity(entity);
			detail.analyse();
			
			entity.insert();
			
			Enviroment.getEnv().getLogBean().endLog();
			
		} catch (Exception e) {
			e.printStackTrace();				
			DBFactory.getThreadDB().executeUpdate("insert into ${schema}.NET_MARGNET_EXCEP (EXCEP_ID,EXCEP_URL,EXCEP_LEVEL) "
					+ "values ('"+System.currentTimeMillis()+MathUtil.random(3)+"','"+href+"','2')");

		}
		
	}
	
}
